import Vue from 'vue'
import VueRouter from 'vue-router'
import { isLogin } from '@/utils/user'
const Login = () => import('@/views/user/Login.vue')
const Chat = () => import('@/views/chat/Chat.vue')
const Test = () => import('@/views/test/index.vue')
const NotFound = () => import('../views/404.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/chat'
  },
  {
    path: '/test',
    name: 'test',
    component: Test
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },{
    path: '/chat',
    name: 'chat',
    component: Chat,
    beforeEnter:(to,form,next) => {
      if(isLogin()){
        next()
      }else{
        next({ name: 'login' })
      }
    }
  },{
    path: '/404',
    name: '404',
    component: NotFound
  },{
    path: '/*',
    redirect: '/404'
  }
]

const router = new VueRouter({
  routes
})

export default router
